/* === LICENSE INFO ===
 * This source file is subject to the GPLv3 license that is bundled with this
 * package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl.txt
 * === end of LICENSE INFO === */

/*==============================================================================
  File Name   : LogWriter.hpp
  Description : Declaration for LogWriter class in GLog module.

  Created on  : 2009-09-29
  Updated on  : 2011-01-30
  Updated by  : Lee Shiou Ming

  Cautions    : (important notes)
  ============================================================================*/

#ifndef LOGWRITER_HPP_
#define LOGWRITER_HPP_

#include "GDateTime/GDateTime.hpp"
#include <string>

using namespace gUtil::GDateTime;


/**
 * @brief All gUtil modules will be wrapped within gUtil namespace.
 */
namespace gUtil
{
/**
 * @brief Namespace for GLog module.
 */
namespace GLog
{
    /**
     * @brief Base interface for actual log output functionalities.
     *
     * It is designed that caller shouldn't interact with log writers directly.
     * Instead, logging request will be forwarded by LogWriterManager to
     * corresponding log writers which are being managed.
     */
    class LogWriter
    {
    public:
        /**
         * @brief An empty destructor.
         */
        virtual ~LogWriter() {}

        /**
         * @brief Interface for appending log message to output.
         *
         * Each subclasses must provides corresponding implementation. Call the
         * default/overridden/overloaded message formatter to apply formatting
         * before streaming log message to output.
         *
         * @param _logMessage
         * [IN] The message which log client wants to append.
         * @param _logLevelString
         * [IN] Subclasses should pass log level string to message formatter.
         * @param _log_msg_time
         * [IN] The time when log request was submitted.
         */
        virtual void append(const std::string& _logMessage,
                const std::string& _logLevelString,
                const ptime& _log_msg_time) = 0;

    protected:
        /**
         * @brief Last log message time.
         */
        GDateTime::ptime m_lastLogMsgTime;

        /**
         * @brief Default implementation that provides subclasses a simple log
         *        message formatting.
         *
         * Prefixes client's log message with date time and log level string,
         * embraced within square brackets. Ends the log entry with a new line.
         *
         * @param _logMessage
         * [IN] The message which log client wants to append.
         * @param _logLevelString
         * [IN] Subclasses are strongly encouraged to include log level string
         *      in log message entry, as it generally makes log analysis easier.
         * @param _log_msg_time
         * [IN] The time when log request was submitted.
         *
         * @return Formatted log message:
         * [<datetime>][<_logLevelString>] <_logMessage><newline>
         */
        virtual std::string formatLogMessage(const std::string& _logMessage,
                const std::string& _logLevelString,
                const GDateTime::ptime& _log_msg_time);

    };  /* end of class LogWriter */

}  /* end of namespace GLog */
}  /* end of namespace gUtil */

#endif  /* LOGWRITER_HPP_ */
